﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using mediatheque.Areas.Admin.Models;

namespace mediatheque.Areas.Admin.Controllers
{
    public class ArtistesController : Controller
    {
        protected Artistes myArtiste = new Artistes();
        //
        // GET: /Admin/Oeuvres/

        public ActionResult Index(FormCollection data)
        {
            if (data.Count > 1)
            {
                artiste a = new artiste
                {
                    firstname = data["firstname"],
                    lastname = data["lastname"]
                };

                if (TryUpdateModel(a))
                {
                    myArtiste.artiste.AddObject(a);
                    myArtiste.SaveChanges();
                }
            }
            return View(myArtiste);
        }

        public ActionResult Delete(int id)
        {
            try
            {
                var a = myArtiste.artiste.First(i => i.id == id);
                myArtiste.artiste.DeleteObject(a);
                myArtiste.SaveChanges();
                return RedirectToAction("Index");
            }
            catch
            {
                return RedirectToAction("Index");
            }
        }
    }
}
